<template>
	<view class="dispensingcard">
		<view class="cardcontent">
			<view class="card_title">
				<u-row class="card_title_row">
					<u-col span="1">
						<u-icon name="order" class="card_icon" size="40"></u-icon>
					</u-col>
					<u-col span="3">
						<view  class="second-font title-font">
							西药方
						</view>
					</u-col>
					<u-col offset="3" span="3">
						<view class="choose-font title-font" v-if="statement=='待提交'" @click="toPath()">
							+新增药品
						</view>
					</u-col>
					<u-col span="1">
						<view v-if="statement=='待提交'">
							<u-icon name="trash" class="card_icon2 title_icon" @click="deletecard(index2)"></u-icon>
						</view>
					</u-col>
				</u-row>
			</view>
			<view class="card_content">
				
				<view v-for="(item,index) in list" :key=index>
					<u-row class="content_urow">
						<u-col offset="1" span="5"  >
							{{item.name}}
						</u-col>
						<u-col offset="3" span="2" class="second-font">
							{{item.quantity}}盒
						</u-col>
						<u-col  span="1">
							<view v-if="statement=='待提交'">
								<u-icon name="trash" class="card_icon2" @click="deleteitem(index)"></u-icon>
							</view>
						</u-col>
					</u-row>
					<u-row class="content_urow">
						<u-col offset="1" span="3" class="second-font">
							{{item.dose}}g*{{item.takeDays}}天
						</u-col>
						<u-col offset="4"span="4" class="third-font">
							用法：{{item.name1}} {{item.name2}}
						</u-col>
					</u-row>
					<view class="separate" />
				</view>
				<!-- <view>
					<u-row class="content_urow">
						<u-col span="6">
							 吉西他滨真(医5)
						</u-col>
						<u-col offset="3" span="2" class="second-font">
							2盒
						</u-col>
						<u-col  span="1">
							<u-icon name="trash" class="card_icon2"></u-icon>
						</u-col>
					</u-row>
					<u-row class="content_urow">
						<u-col offset="1" span="3" class="second-font">
							0.5g*24
						</u-col>
						<u-col offset="4"span="4" class="third-font">
							用法：bit 外用
						</u-col>
					</u-row>
					<view class="separate" />
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:["index2"],
		data() {
			return {
				list:[],
				statement:'',
			};
		},
		methods:{
			toPath(){
				uni.redirectTo({
					url:"doctor_dispensing_detail_prescriptionlist?index="+this.index2
				})
			},
			deleteitem(index){
				this.list.splice(index,1);
				// console.log(this.list);
				getApp().globalData.worktable[this.index2].drugs=this.list
			},
			deletecard(index){
				console.log(index);
				getApp().globalData.worktable.splice(index,1);
				// uni.navigateBack();
				uni.redirectTo({
					url:"doctor_dispensing_detail_prescription"
				})
			}
		},
		created(){
			console.log(getApp().globalData.worktable[this.index2].drugs);
			this.list=getApp().globalData.worktable[this.index2].drugs;
			this.statement=getApp().globalData.worktable[this.index2].statement;
			// this.list.forEach((value , index) => {
			// 	value['name1'] = '',
			// 	value['name2'] = ''
			// })
			// console.log(this.list);
			this.list.forEach(function(temp){  
				uni.request({
				    url: getApp().globalData.hostip+'Demo/usage/getById?id='+temp.usageCode, 
				    data: {
				    },
					fail:(fa) =>{
						console.log(fa)
					},
				    success: (res) => {
						// console.log("test"+res.data.frequency.usageName);
						// console.log(temp);
						temp.name1=res.data.frequency.usageName
				    }
				});
				uni.request({
				    url: getApp().globalData.hostip+'Demo/frequency/getById?id='+temp.frequencyCode, 
				    data: {
				    },
					fail:(fa) =>{
						console.log(fa)
					},
				    success: (res) => {
						temp.name2=res.data.frequency.frequencyNameAbbr
				    }
				});
				// console.log(temp)
			});
		}
	};
</script>

<style scoped lang="scss">
	.dispensingcard{
		margin: 20rpx;
		border-radius: 20rpx;
		border: 1px solid #d4d4d4;
		background-color: #FFFFFF;
	}
	.card_title{
		border-radius: 20rpx 20rpx 0 0;
		background-color: #ecf5ff;
	}
	.title-font{
		/* margin-top:28rpx; */
		font-size: 36rpx;
		text-align: center;
		padding: 20rpx 0;
	}
	.card_icon{
		color: #2b85e4;
		padding: 24rpx;
	}
	.card_icon2{
		color: #dd6161;
	}
	.choose-font{
		font-size: 30rpx;
		padding: 28rpx 0;
	}
/* 	.card_content{
		margin: 20rpx;
	} */
	.medicine_info{
		display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
		overflow: hidden;
		word-break: break-all;  /* break-all(允许在单词内换行。) https://www.w3school.com.cn/cssref/pr_word-break.asp*/
		text-overflow: ellipsis;  /* 超出部分省略号 */
		-webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
		-webkit-line-clamp: 1; /** 显示的行数 **/
		
	}
	.third-font{
		font-size: 24rpx;
	}
	.content_urow{
		margin: 5rpx;
	}
	.title_icon{
		padding: 32rpx;
	}
</style>
